package main

import (
	"os"
	"log"
	"encoding/json"
)

type Contact struct {
	Name string `json:"name"`
	Title string `json:"title"`
	Contact struct {
		Home string `json:"home"`
		Cell string `json:"cell"`
	} `json:"contact"`
}

var JSON = `{
	"name":"Gop",
	"title":"ppp",
	"contact":{
		"home":"myHome",
		"cell":"中文"
		}
	}`


func main() {

	var c Contact
	json.Unmarshal([]byte(JSON), &c)
	json.NewEncoder(os.Stdout).Encode(&c)
	bytes, _ := json.Marshal(&c)
	log.Println(string(bytes))

	JSON = string(bytes)
	str2Map, _ := jsonStr2Map(JSON)

	log.Println("str2Map.....")
	log.Println(str2Map["name"])
	log.Println(str2Map["contact"])
	log.Println(str2Map["contact"].(map[string]interface{})["cell"])

	data, _ := json.MarshalIndent(&str2Map, "", "    ")
	log.Println(string(data))
	data, _ = json.Marshal(&str2Map)
	log.Println(string(data))

}

/**
	json字符串转map
 */
func jsonStr2Map(jsonStr string) (map[string]interface{}, error)  {

	var c = make(map[string]interface{})
	json.Unmarshal([]byte(jsonStr), &c)
	return c, nil

}